<?php

namespace app\admin\model\pt;

use think\Model;
use app\admin\model\pt\Depart as DepartModel;
use app\admin\model\pt\Job as JobModel;
use app\admin\model\pt\Labor as LaborModel;


class Person extends Model
{

    

    

    // 表名
    protected $name = 'pt_person';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'sex_text',
        'user_type_text',
        'white_black_text'
    ];
    

    
    public function getSexList()
    {
        return ['0' => __('Sex 0'), '1' => __('Sex 1'), '2' => __('Sex 2')];
    }

    public function getStatusList()
    {
        return ['hidden' => __('隐藏'), 'normal' => __('正常')];
    }

    public function getUserTypeList()
    {
        return ['self' => __('User_type self'), 'intern' => __('User_type intern'), 'labor' => __('User_type labor')];
    }

    public function getWhiteBlackList()
    {
        return ['none' => __('White_black none'), 'white' => __('White_black white'), 'black' => __('White_black black')];
    }

    public function getConfirmIdCardList()
    {
        return ['0' => __('未认证'), '1' => __('已认证'), '2' => __('认证失败')];
    }


    public function getSexTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['sex']) ? $data['sex'] : '');
        $list = $this->getSexList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getUserTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['user_type']) ? $data['user_type'] : '');
        $list = $this->getUserTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getWhiteBlackTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['white_black']) ? $data['white_black'] : '');
        $list = $this->getWhiteBlackList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getConfirmIdCardTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['confirm_idcard']) ? $data['confirm_idcard'] : '');
        $list = $this->getConfirmIdCardList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    
    public function job()
    {
        return $this->belongsTo(JobModel::class, 'pt_job_id', 'id')->setEagerlyType(1);;
    }

    public function depart()
    {
        return $this->belongsTo(DepartModel::class, 'pt_depart_id', 'id')->setEagerlyType(1);;
    }

    public function labor()
    {
        return $this->belongsTo(LaborModel::class, 'pt_labor_id', 'id')->setEagerlyType(1);;
    }

}
